import React, { Component } from 'react';
import { StyleSheet, Text, Alert, Dimensions, TouchableOpacity } from "react-native";
import { style } from '../theme/style';

import { API, API_GENERATE } from '../config/api';
import ValidateDataUtil from '../utils/ValidateDataUtil';
import HTTP from '../utils/http'

const ScreenWidth = Dimensions.get('window').width;
const ScreenHeight = Dimensions.get('window').height;
const scale = ScreenWidth / 375;

export class CodeStartCpt extends Component {
	constructor(props) {
		super(props);
	}

	_sendCode () {
		let resout = null;
		resout = !ValidateDataUtil.isPhone(this.props.phone) ? true : false;

		if (this.props.phone == '') {
			Alert.alert('', '请输入你手机号码', [
				{ text: '确认', onPress: () => { console.log('确认') } }
			])
		} else if (resout) {
			Alert.alert('', '手机号码不正确，请重新输入', [
				{ text: '确认', onPress: () => { console.log('确认') } }
			])
		} else {
			Alert.alert('确认手机号码', `我们将发送短信验证码到这个号码：\n${this.props.phone}`, [
				{ text: '取消', onPress: () => { console.log('取消') } },
				{ text: '好', onPress: () => { this._sendCodeOk() } },
			]);
		}
	}
	_sendCodeOk () {
		this.props._getData({ onoff: false });
		const requestObj = {};
		requestObj.bizId = '2';
		requestObj.mobile = this.props.phone;
		HTTP.POST(API_GENERATE(API.PASSWORD_CODE), requestObj).then((Result) => {
			console.log('发送短信验证码：Result');
			console.log(Result);
			if (Result) {
				//this.props._getData({ onoff: false });
			}
		})

	}
	render () {
		return (
			<TouchableOpacity style={styles.commitYzmBox} onPress={this._sendCode.bind(this)}>
				<Text style={styles.commitYzm}>发送验证码</Text>
			</TouchableOpacity>
		)
	}
}

const styles = StyleSheet.create({
	commitYzmBox: {
		alignSelf: 'center',
		padding: 6 * scale,
		height: 26 * scale,
		borderRadius: 13 * scale,
		backgroundColor: style.color.themeColor,
		justifyContent: 'center',
		alignItems: 'center'
	},
	commitYzm: {
		color: style.color.white,
		fontSize: 13 * scale
	}
})